package com.wenx.unit2;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class SharesMain {
    public static void main(String[] args) {
        List<Shares> shares = Arrays.asList(new Shares("2018-11",286),
                new Shares("2018-10",234),
                new Shares("2018-03",221),
                new Shares("2018-09",243),
                new Shares("2018-05",267),
                new Shares("2018-08",212),
                new Shares("2018-07",262));

        Map<String, Integer> collect = shares.stream()
                //.sorted(Comparator.comparing(Shares::getDate))
                .collect(Collectors.groupingBy(Shares::getDate,Collectors.summingInt(Shares::getMoney)));
        collect.entrySet().stream()
                .sorted(Map.Entry.comparingByKey())
                .forEachOrdered(m -> System.out.println("m = " + m.getKey()));

//        collect.forEach((k,v)->{
//            System.out.println("k = " + k + " v = " + v);
//        });

    }
}
